var status = 0;
var choice;
var itemxh = new Array("5150040", "5150064", "5150126", "5150100", "5150119", "5150135", "5150139", "5210001", "5210000", "5050100", "5051001", "5220040", "5390004", "5390006", "5390010", "5390019", "5390020", "5390022", "5390031", "5079001", "5079002", "5079005", "5390003", "5390005", "5390007", "5390008", "5390018", "5390030", "5390034");
var itemxhcost = new Array("10000", "10000", "10000", "10000", "10000", "10000", "10000", "10000", "2000", "5000", "15000", "1000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000", "5000");
function start() {
	status =  - 1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode ==  - 1)
		cm.dispose();
	else {
		if (status == 0 && mode == 0) {
			cm.dispose();
			return;
		} else if (status >= 1 && mode == 0) {
			cm.sendOk("真的不考虑购买一些东西么？好的,欢迎下次继续光临！");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			choices = "请选择您要购买的道具  #rPS：购买前请确认背包有足够的空间。\r\n#r#e #n#b";
			for (var i = 0; i < itemxh.length; i++) {
				choices += "\r\n#b#L" + i + "##v" + itemxh[i] + "##z" + itemxh[i] + "#　#d需要#r" + itemxhcost[i] + "#d点卷#k#l";
			}
			cm.sendSimpleS("" + choices, 2);
		} else if (status == 1) {
			cm.sendGetNumber("你选择的商品为#b#v" + itemxh[selection] + "#售价为：" + itemxhcost[selection] + "点卷/张\r\n请输入你购买的数量", 1, 1, cm.getPlayer().getCSPoints(1));
			choice = selection;
		} else if (status == 2) {
			fee = selection;
			money = fee * itemxhcost[choice];
			if (fee < 0) {
				cm.sendOk("不能输入0.或者你没有足够的点卷支付你要买的数量.!");
				cm.dispose();
			} else if (cm.getPlayer().getCSPoints(1) < money) {
				cm.sendOk("购买失败，你没有" + money + "点卷");
				cm.dispose();
            } else if (cm.getSpace(1) < 3 || cm.getSpace(2) < 3 || cm.getSpace(3) < 3 || cm.getSpace(4) < 3 || cm.getSpace(5) < 3) {
                cm.sendOk("您的背包空间不足，请保证每个栏位至少3格的空间，以避免失败。");
                cm.dispose();
			} else {
				cm.gainNX( - money);
				cm.gainItem(itemxh[choice], fee);
				cm.worldSpouseMessage(0x0F, "[点卷商城] :玩家:" + "[" + cm.getChar().getName() + "]" + " " + "在" + cm.getServerName() + "点卷商城喇叭道具区进行了赞助消费.");
				cm.sendOk("恭喜，购买成功。您的每一次赞助消费我们都很感激！");
				cm.dispose();
			}
		}
	}
}
